home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / misc / amigem.lha / amigem / exec / messages.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-19  |  2.8 KB  |  124 lines

  1. #include <exec/execbase.h>
  2. #include <exec/memory.h>
  3. #include <exec/semaphores.h>
  4. #include <exec/devices.h>
  5. #include <exec/io.h>
  6. #include <clib/_exec.h>
  7. #include <stdio.h>
  8.  
  9. #include <amigem/fd_lib.h>
  10. #define LIBBASE struct ExecBase *SysBase
  11.  
  12. FD1(62,struct Message *,GetMsg,struct MsgPort *port,A0)
  13. {
  14.   struct Message *msg;
  15.   Forbid();
  16.     msg=(struct Message *)RemHead(&port->mp_MsgList);
  17.   Permit();
  18.   return msg;
  19. }
  20.  
  21. FD2(61,void,PutMsg,struct MsgPort *port,A0,struct Message *msg,A1)
  22. {
  23.   Forbid();
  24.     msg->mn_Node.ln_Type=NT_MESSAGE;
  25.     AddTail(&port->mp_MsgList,&msg->mn_Node);
  26.     switch(port->mp_Flags&PF_ACTION)
  27.     {
  28.       case PA_SIGNAL:
  29.         Signal((struct Task *)port->mp_SigTask,port->mp_SigBit);
  30.         break;
  31.       case PA_SOFTINT:
  32.         Cause((struct Interrupt *)port->mp_SoftInt);
  33.         break;
  34.       case PA_IGNORE:
  35.         break;
  36.     }
  37.   Permit();
  38. }
  39.  
  40. FD1(63,void,ReplyMsg,struct Message *msg,A1)
  41. {
  42.   struct MsgPort *port;
  43.   if((port=msg->mn_ReplyPort)==NULL)
  44.     msg->mn_Node.ln_Type=NT_FREEMSG;
  45.   else
  46.   {
  47.     Forbid();
  48.       msg->mn_Node.ln_Type=NT_REPLYMSG;
  49.       AddTail(&port->mp_MsgList,&msg->mn_Node);
  50.       switch(port->mp_Flags&PF_ACTION)
  51.       {
  52.         case PA_SIGNAL:
  53.           Signal((struct Task *)port->mp_SigTask,port->mp_SigBit);
  54.           break;
  55.         case PA_SOFTINT:
  56.           Cause((struct Interrupt *)port->mp_SoftInt);
  57.           break;
  58.         case PA_IGNORE:
  59.           break;
  60.       }
  61.     Permit();
  62.   }
  63. }
  64.  
  65. FD1(64,struct Message *,WaitPort,struct MsgPort *port,A0)
  66. {
  67.   if(port->mp_MsgList.lh_Head->ln_Succ==NULL)
  68.     Wait(1<<port->mp_SigBit);
  69.   return (struct Message *)port->mp_MsgList.lh_Head;
  70. }
  71.  
  72. FD0(111,struct MsgPort *,CreateMsgPort)
  73. {
  74.   struct MsgPort *mp;
  75.   if((mp=(struct MsgPort *)AllocVec(sizeof(struct MsgPort),MEMF_PUBLIC|MEMF_CLEAR))!=NULL)
  76.   {
  77.     BYTE sb;
  78.     if((sb=AllocSignal(-1))!=-1)
  79.     {
  80.       mp->mp_SigBit=sb;
  81.       mp->mp_MsgList.lh_Head=(struct Node *)&mp->mp_MsgList.lh_Tail;
  82.       /* mp->mp_MsgList.lh_Tail=NULL; */
  83.       mp->mp_MsgList.lh_TailPred=(struct Node *)&mp->mp_MsgList.lh_Head;
  84.       /* mp->mp_Flags=PA_SIGNAL; */
  85.       mp->mp_SigTask=FindTask(NULL);
  86.       return mp;
  87.     }
  88.     FreeVec(mp);
  89.   }
  90.   return NULL;
  91. }
  92.  
  93. FD1(112,void,DeleteMsgPort,struct MsgPort *port,A0)
  94. {
  95.   if(port!=NULL)
  96.   {
  97.     FreeSignal(port->mp_SigBit);
  98.     FreeVec(port);
  99.   }
  100. }
  101.  
  102. FD1(65,struct MsgPort *,FindPort,STRPTR name,A1)
  103. {
  104.   return (struct MsgPort *)FindName(&SysBase->PortList,name);
  105. }
  106.  
  107. FD1(59,void,AddPort,struct MsgPort *port,A1)
  108. {
  109.   port->mp_Node.ln_Type=NT_MSGPORT;
  110.   port->mp_MsgList.lh_Head=(struct Node *)&port->mp_MsgList.lh_Tail;
  111.   port->mp_MsgList.lh_Tail=NULL;
  112.   port->mp_MsgList.lh_TailPred=(struct Node *)&port->mp_MsgList.lh_Head;
  113.   Forbid();
  114.     Enqueue(&SysBase->PortList,&port->mp_Node);
  115.   Permit();
  116. }
  117.  
  118. FD1(60,void,RemPort,struct MsgPort *port,A1)
  119. {
  120.   Forbid();
  121.     Remove(&port->mp_Node);
  122.   Permit();
  123. }
  124.